<template>
	<div class="nav-bar-item" @click="itemClick">
		<div v-if="isActive" class="item-icon-active">
			<slot name="item-icon-active"></slot>
		</div>
		<div v-else class="item-icon">
			<slot name="item-icon"></slot>
		</div>
		<div class="item-text">
			<slot name="item-text"></slot>
		</div>
	</div>
</template>

<script>
	export default {
		name:'navBarItem',
		props:{
			path:String
		},
		methods:{
			itemClick(){
				if(this.$route.path !== this.path){
					this.$router.push(this.path)
				}
			}
		},
		computed:{
			isActive(){
				return this.$route.path.indexOf(this.path) !== -1
			}
		}
	}
</script>

<style>
	.nav-bar-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	.item-icon-active,.item-icon {
		width: 20px;
		height: 20px;
	}
	.item-text span {
		text-align: center;
		font-size: 14px;
	}
</style>
